﻿using System;
using NHibernate.Validator.Constraints;

namespace DataStore.Domain
{
    /// <summary>
    /// Cover of the document
    /// </summary>
    [Serializable]
    public class Cover : IEquatable<Cover>
    {
        /// <summary>
        /// Gets or sets the id.
        /// </summary>
        /// <value>The id.</value>
        public virtual Guid Id { get; set; }
        /// <summary>
        /// Gets or sets the path to the cover image.
        /// </summary>
        /// <value>The path.</value>
        [NotNull]
        public virtual Link Path { get; set; }
        /// <summary>
        /// Gets or sets the type of the cover image.
        /// </summary>
        /// <value>The type.</value>
        public virtual CoverType Type { get; set; }
        /// <summary>
        /// Gets or sets the size of the cover image.
        /// </summary>
        /// <value>The size.</value>
        public virtual CoverSize Size { get; set; }
        /// <summary>
        /// Gets or sets the description.
        /// </summary>
        /// <value>The description.</value>
        public virtual string Description { get; set; }
        /// <summary>
        /// Gets or sets a value indicating whether this cover is default.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this cover is default; otherwise, <c>false</c>.
        /// </value>
        public virtual bool IsDefault { get; set; }

        #region ToString

        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            return Path.Uri.ToString();
        }

        #endregion

        #region Equality

        /// <summary>
        /// Equalses the specified other.
        /// </summary>
        /// <param name="other">The other.</param>
        /// <returns></returns>
        public virtual bool Equals(Cover other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return other.Id.Equals(Id);
        }

        /// <summary>
        /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
        /// <returns>
        /// 	<c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public override bool Equals(object obj)
        {
            return Equals(obj as Cover);

        }

        /// <summary>
        /// Returns a hash code for this instance.
        /// </summary>
        /// <returns>
        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
        /// </returns>
        public override int GetHashCode()
        {
            return Id.GetHashCode();
        }

        /// <summary>
        /// Implements the operator ==.
        /// </summary>
        /// <param name="left">The left.</param>
        /// <param name="right">The right.</param>
        /// <returns>The result of the operator.</returns>
        public static bool operator ==(Cover left, Cover right)
        {
            return Equals(left, right);
        }

        /// <summary>
        /// Implements the operator !=.
        /// </summary>
        /// <param name="left">The left.</param>
        /// <param name="right">The right.</param>
        /// <returns>The result of the operator.</returns>
        public static bool operator !=(Cover left, Cover right)
        {
            return !Equals(left, right);
        }

        #endregion
    }
}
